﻿using GN.Pay.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.DefaultImpl
{
    /// <summary>
    /// 默认交易退款申请结果
    /// </summary>
    [Serializable]
    public class TradeRefundApplyResult : ATradeChannelResult, ITradeRefundApplyResult
    {
        /// <summary>
        /// 实例化 DefaultTradeRefundApplyResult 类新实例
        /// </summary>
        /// <param name="channel">通道</param>
        /// <param name="refundNo">退款号</param>
        /// <param name="tradeNo">交易号</param>
        /// <param name="refundMoney">退款金额</param>
        /// <param name="refundFee">退款费用</param>
        /// <param name="refundTime">退款时间</param>
        /// <param name="resultState">结果状态</param>
        /// <param name="resultStateMessage">结果状态消息</param>
        public TradeRefundApplyResult(IChannel channel, string refundNo, string tradeNo, decimal refundMoney,
            decimal refundFee, DateTime? refundTime, TradeApplyResultState resultState,
            string resultStateMessage) : base(channel)
        {
            this.RefundNo = refundNo;
            this.TradeNo = tradeNo;
            this.RefundMoney = refundMoney;
            this.RefundFee = refundFee;
            this.RefundTime = refundTime;
            this.ResultState = resultState;
            this.ResultStateMessage = resultStateMessage;
        }
               
        /// <summary>
        /// 获取结果状态
        /// </summary>
        public TradeApplyResultState ResultState { get; private set; }

        /// <summary>
        /// 获取结果状态消息
        /// </summary>
        public string ResultStateMessage { get; private set; }

        /// <summary>
        /// 获取退款编号
        /// </summary>
        public string RefundNo { get; private set; }

        /// <summary>
        /// 获取交易号
        /// </summary>
        public string TradeNo { get; private set; }

        /// <summary>
        /// 获取退款金额
        /// </summary>
        public decimal RefundMoney { get; private set; }

        /// <summary>
        /// 获取退款费用
        /// </summary>
        public decimal RefundFee { get; private set; }

        /// <summary>
        /// 获取退款时间
        /// </summary>
        public DateTime? RefundTime { get; private set; }

        /// <summary>
        /// 验证
        /// </summary>
        public void Validation()
        {
            if (string.IsNullOrWhiteSpace(this.ChannelId))
            {
                this.ThrowChannelValidationException
                   ("TradeNo 为 null 或空白");
            }
            if (this.RefundFee < 0)
            {
                this.ThrowChannelValidationException
                    ("RefundFee 小于零");
            }
            if (this.RefundMoney <= 0)
            {
                this.ThrowChannelValidationException
                    ("RefundMoney 小于或等于零");
            }
            if (string.IsNullOrWhiteSpace(this.RefundNo))
            {
                this.ThrowChannelValidationException
                    ("RefundNo 为 null 或空白");
            }
            if (string.IsNullOrWhiteSpace(this.TradeNo))
            {
                this.ThrowChannelValidationException
                    ("TradeNo 为 null 或空白");
            }
        }

    }
}
